package project3;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.Socket;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Router {
	public static String routerId = "Tor61Router-";
	public static int routerData = 0x0FAC0000;
	
	// Responsible for handling the TCP connections with other routers
	private static Map<String, Socket> tcpConn;
	private static Map<String, DataInputStream> tcpConnIn;
	private static Map<String, DataOutputStream> tcpConnOut;
	
	
	public static void main(String[] args) {
		if (args.length != 1) {
			System.out.println("Usage: java Router <router-num>");
			System.exit(-1);
		}
		
		tcpConn = new ConcurrentHashMap<String, Socket>();
		tcpConnIn = new ConcurrentHashMap<String, DataInputStream>();
		tcpConnOut = new ConcurrentHashMap<String, DataOutputStream>();
		
		int id = Integer.parseInt(args[0]);
		routerId += (routerData >> 16) + "-" + String.format("%04d", ((routerData & 0xFFFF) | id));
		
	}
	
	public static void sendMassageToRouter(String ipPort, String message) throws Exception {
		if (!tcpConn.containsKey(ipPort)) {
			// TODO: Connect to the given ip:port
			// TODO: Add the associate inputStream and the outputStream
			
		}
		
	}
	
}
